package model;
import java.util.ArrayList;
import java.util.Observer;

public class TemperatureModel extends java.util.Observable  {
	private ArrayList<Observer> observers;
	
	public TemperatureModel() {
		observers = new ArrayList<Observer>();
	}
	
	private double temperatureC = 0.0;
	
	public double getF() {
		return (temperatureC * 9.0 / 5.0) + 32.0;
	}

	public double getC() {
		return temperatureC;
	}
	
	public double getK() {
		return temperatureC+273.15;
	}

	public void setF(double tempF) {
		temperatureC = (tempF - 32.0) * 5.0 / 9.0;
		setChanged();
		notifyObservers();
	}
	
	public void setK(double tempK) {
	    temperatureC = tempK-273.15;
		setChanged();
		notifyObservers();
	}


	public void setC(double tempC) {
		temperatureC = tempC;
		setChanged();
		notifyObservers();
	}
	
	public double getAbsMinC(){
		return -273.15;
	}
	
	public void attach(Observer obs) {
		observers.add(obs);
	}
	
	public void detach(Observer obs) {
		observers.remove(obs);
	}
	
	public void detach(int obsInd) {
		observers.remove(obsInd);
	}
	
	@Override
	public void notifyObservers() {
		super.notifyObservers();
		for(Observer obs: observers) {
			synchronized(obs) {
				obs.update(this, null);
			}
		}
	}

	
}
